﻿/*
获取URL中最后一项参数的值
*/

//以下是函数的写法
function GetParam()
{
    var url = document.location.href;
    var name = "";
    if (url.indexOf("=") > 0)
    {
        name = url.substring(url.indexOf("=") + 1, url.length)
    }
    return name;
}

/*
获取指定的URL参数值
URL:http://www.blogjava.net/blog?name=bainian
参数：paramName URL参数
调用方法:getParam("name")
返回值:bainian
*/
//1.
function getParam(paramName)
{
    var paramValue = "";
    var isFound = false;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1)
    {
        var arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&");
        var i = 0;
        while (i < arrSource.length && !isFound)
        {
            if (arrSource[i].indexOf("=") > 0)
            {
                if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase())
                {
                    paramValue = arrSource[i].split("=")[1];
                    isFound = true;
                }
            }
            i++;
        }
    }
    return paramValue;
}


//2.
function Request(sName)
{

    /*
    get last loc. of ?
    right: find first loc. of sName
    +2
    retrieve value before next &  
    */

    var sURL = document.location.href;
    var iLensName = sName.length;

    //retrieve loc. of sName
    var iStart = sURL.indexOf('?' + sName + '=') //limitation 1
    if (iStart == -1)
    {//not found at start
        iStart = sURL.indexOf('&' + sName + '=')//limitation 1
        if (iStart == -1)
        {//not found at end
            return 0; //not found
        }
    }

    iStart = iStart + +iLensName + 2;
    var iTemp = sURL.indexOf('&', iStart); //next pair start
    if (iTemp == -1)
    {//EOF
        iTemp = sURL.length;
    }
    return sURL.slice(iStart, iTemp);
}